<?php


namespace app\listener;


use app\data\model\DataUser;
use app\mall\logic\walletLogic;
use think\facade\Db;

class UserRecharge
{
    public function handle($rechargeOrder)
    {
        $user = DataUser::find($rechargeOrder['u_id']);
        $pay_amount = $rechargeOrder['recharge_money'];

        //分销给上级用户积分提成
        if ($user['pid1']>1){
            $commission_rate = sysdata('recharge_integral_commission_rate');//分佣比例%
            $commission_integral = bcMath($pay_amount,$commission_rate/100,'*');
            walletLogic::wallet_detailed_add($user['pid1'],$commission_integral,7,2,0,'add','分佣');//增加记录
            Db::table('one_user_wallet')->where('u_id','=',$user['pid1'])->inc('integral',$commission_integral)->update();//增加余额
        }
    }
}